# Path to the common makefiles
SHARE = ../../make

# Name and type of the (sub)project
META = tests

# Version number
MAJOR = 0
MINOR = 0
REVISION = 0

# Include the common makefile
include $(SHARE)/include.make

TESTS = $(shell ls *.body)

LFLAGS = -lm
CFLAGS = #-ffloat-store

all:
	make -r myall

myall: $(TESTS:%.body=%.test)

clean: myclean

myclean:
	rm -f *.txt *.o *.c *.in *.aterm *.out *.out.decl *.out.body

%.test: %.gcc.txt %.full.txt %.partial.txt #%.partial.out %.partial.out2
	@if diff -u $*.gcc.txt $*.full.txt; then echo -e "$* (full)    \033[37m\033[1mOK\033[0m"; fi 
	@if diff -u $*.gcc.txt $*.partial.txt; then echo -e "$* (partial) \033[37m\033[1mOK\033[0m"; fi 
#	@if diff -u $*.partial.out $*.partial.out2; then echo -e "$* (idempotence)    \033[37m\033[1mOK\033[0m"; fi 

%.txt: %.o
	@./$< > $@

%.o: %.c
	@gcc -o $@ $< $(CFLAGS) $(LFLAGS)

%.gcc.c: preamble postamble default.decl default.init %.decl %.init %.body 
	@cat preamble default.decl $*.decl default.init $*.init $*.body postamble > $@

%.full.in: default.decl default.init %.decl %.init %.body
	@cat default.decl $*.decl default.init $*.init $*.body | cpp > $@

%.partial.in: default.decl default.init mark %.decl %.body
	@cat default.decl $*.decl default.init mark $*.body | cpp > $@

%.out: %.in ../src/pepci
	@../src/pepci -i $< -o $@ $(LFLAGS)
	@../cnf $@

%.out2: %.out ../src/pepci
	@../src/pepci -i $< -o $@ $(LFLAGS)
	@../cnf $@
	      
%.full.c: preamble postamble %.full.out
	@cat preamble $*.full.out postamble > $@

%.out.decl: %.out
	@grep -B 1000 "mark();" $< | grep -v "mark();" > $@

%.out.body: %.out
	@grep -A 1000 "mark();" $< > $@

%.partial.c: preamble postamble %.partial.out.decl %.init %.partial.out.body
	@cat preamble $*.partial.out.decl $*.init $*.partial.out.body postamble > $@

.PRECIOUS: %.full.in %.partial.in

